// This class for creating new app domain for scripting environment, then create instance of ScriptManager in new domain

#pragma once
#include <windows.h>
#include "ScriptManager.h"
#include "Log.h"
#include "KeyboardHook.h"
#include "KeyEventArgs.h"
//#include "KeyboardHook.h"

using namespace System;
using namespace System::Reflection;

namespace GTA
{

	public ref class ScriptDomain //: MarshalByRefObject
	{

	private:
		static AppDomain^ _scriptdomain;
	public:
		static ScriptDomain^ Instance; // WorkerThread will use this
		static AppDomain^ GetScriptDomain(); // returns the scripts appdomain
		ScriptDomain::ScriptDomain();
		AppDomain^ ScriptDomain::CreateScriptDomain(); // Create the script domain
		ScriptManager^ ScriptDomain::CreateScriptManager(AppDomain^ appdomain); // Create the script loader & load the scripts into our scriptdomain

		bool environmentBuilt; // has the scriptdomain been built & loaded
		String^ scriptDomainName; // name of script domain
		ScriptManager^ scriptmanager; // the scriptmanager instance


		static System::Reflection::Assembly^ ScriptDomain::domain_AssemblyResolver( Object^ sender, ResolveEventArgs^ args );
		static void ScriptDomain::domain_UnhandleException(Object^ sender, UnhandledExceptionEventArgs^ e);

		void ScriptDomain::UnloadScriptDomain();
		void ScriptDomain::ReloadScriptDomain();

	};
};